﻿
using BCGM.MedicalWisdom.IServices;
using BCGM.MedicalWisdom.Services.BASE;
//using BCGM.MedicalWisdom.IRepository.Base;
using BCGM.MedicalWisdom.Model;
using System.Threading.Tasks;
using BCGM.MedicalWisdom.Repository.BASE;
using BCGM.MedicalWisdom.Common.Helper;
using AutoMapper;
using SqlSugar.DistributedSystem.Snowflake;
using System.Xml.Linq;
using Microsoft.AspNetCore.Http;
using BCGM.MedicalWisdom.Common.AliYun;
using StackExchange.Redis;
using System;
using BCGM.MedicalWisdom.Model.Models.Patients;
using BCGM.MedicalWisdom.Model.ViewModels.PatientsDTO;

namespace BCGM.MedicalWisdom.Services
{
    /// <summary>
    /// 患者用户注册
    /// </summary>
    public class PatientUserServices : BaseServices<PatientUser>,IPatientUserServices
    {
        private readonly IHttpContextAccessor _accessor;
        private readonly IBaseRepository<PatientUser> _dal;
        private readonly IMapper _mapper;   //AutoMapper接口需要依赖注入
        //private ISession MySession => HttpContext.Session;
        public PatientUserServices(IBaseRepository<PatientUser> dal, IMapper mapper)
        {
            this._dal = dal;
            base.BaseDal = dal;
            _mapper = mapper;
        }
        /// <summary>
        /// 患者注册账号
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<int> UserAdds(PatientUserAddDTO input)
        {
            //密码md5加密
            input.Pwd = MD5Helper.MD5Encrypt16(input.Pwd);
            //AutoMapper数据映射，由PatientUserLoginDTO类型映射为PatientUser类型
            PatientUser patientUser = _mapper.Map<PatientUser>(input);
            //patientUser.CreateBy=  _accessor.HttpContext?.User?.Identity?.Name;//获取当前登录人的姓名
            patientUser.CreateTime = DateTime.Now;
            //账号生成使用手机号
            patientUser.Accountnumber = patientUser.Phone;
            //返回受影响行数
             
            return await _dal.Add(patientUser);
        }
    }
}